<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" type="text/css" href="css/body.css" />

    <meta charset="UTF-8">

    <title>Health Login Form</title>

    <script src="js/prefixfree.min.js"></script>

</head>

<body>
    <div class="body"></div>
    <div class="grad"></div>
    <div class="headleft">
        <div>Health<span>Login</span></div>
    </div>
    <br>
    <div class="login">
        <input type="text" placeholder="username" name="user" id="user"><br>
        <input type="password" placeholder="password" name="password" id="password"><br>
        <input type="button" value="Login" onclick=check()>
        <script type="text/javascript">
            // document.cookie = 'name=jack;password=123';
            function Login() {
                //var btn = document.getElementsByTagName("button")[0];
                // console.log("事件1");
                // alert("hello Login");
                // 异步对象
                var host = window.location.host;
                console.log(host);
                $.ajax({
                    type: "POST",
                    url: 'http://' + host + '/login/checkuser',
                    // jsonp: "callbackparam",
                    async: false, //同步：意思是当有返回值以后才会进行后面的js程序。
                    data: "user=" + document.getElementById("user").value + '&password=' + document.getElementById("password").value, //请求需要发送的处理数据
                    success: function(mess, textStatus) {
                        //var cook = document.cookie;
                        //alert("cook:" + cook);
                        console.log(mess);

                        if (mess.toUpperCase() == "OK") { //根据返回值进行跳转
                            //alert('http://' + host + '/healthsystem/ris/studys.html');
                            location.href = 'http://' + host + '/healthsystem/ris/studys.html';
                            //window.location = 'http://' + host + '/view/imageview.html';
                        } else {
                            alert("message from server: " + mess);
                            // $("#errorplace").show();
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        console.log(XMLHttpRequest);
                        // 状态码
                        console.log(XMLHttpRequest.status);
                        // 状态
                        console.log(XMLHttpRequest.readyState);
                        // 错误信息   
                        console.log(textStatus);
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        console.log(XMLHttpRequest);
                    }
                });

            }
        </script>
        <script type="text/javascript">
            function check() {
                if (document.getElementById("user").value == "") {
                    alert("没有输入用户名！");
                    return false;
                } else if (document.getElementById("password").value == "") {
                    alert("没有输入密码！");
                    return false;
                } else {
                    //alert(window.location.port);
                    Login();
                    return true;
                }
            }
        </script>
    </div>

    <script src='lib/jquery.js'></script>

</body>

</html>